package com.bloveoacom.weichi.activity;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;

import com.bloveoacom.base.BaseList2Activity;
import com.bloveoacom.base.UserInfoBean;
import com.bloveoacom.http.HttpMethods;
import com.bloveoacom.http.RxHelper;
import com.bloveoacom.observer.BaseSubscriber2;
import com.bloveoacom.util.ActivityUtil;
import com.bloveoacom.util.GlideUtil;
import com.bloveoacom.util.StringUtils;
import com.bloveoacom.weichi.R;
import com.bloveoacom.weichi.bean.ActivitysBean;
import com.bloveoacom.weight.LlkjToolBar;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import butterknife.BindView;

import static com.bloveoacom.util.Constant.ACTIVITY_STATUS_JINXINZHONG;
import static com.bloveoacom.util.Constant.ACTIVITY_STATUS_WEIKAISHI;
import static com.bloveoacom.util.Constant.ACTIVITY_STATUS_YIJIESHU;

/**
 * author: zhu.px
 * e-mail: 1271901673@qq.com
 * time  : 2018/7/12
 * desc  : 我的关注或者粉丝
 */
public class BuyRecordActivity extends BaseList2Activity<ActivitysBean> {

    @BindView(R.id.title_bar)
    LlkjToolBar titleBar;

    @Override
    public int getLayoutResId() {
        return R.layout.layout_refresh_title_share;
    }

    @Override
    public void initView() {
        super.initView();
        titleBar.setToolBar("购票记录",
                true, "", R.drawable.ic_back, true, "", LlkjToolBar.isNull);
    }


    @Override
    protected View getViewSetTB() {
        return titleBar;
    }

    @Override
    public void getBundleExtras(Bundle extras) {

    }

    @Override
    protected int getItemLayout() {
        return R.layout.rv_item_activity;
    }

    @Override
    protected void convertView(BaseViewHolder helper, ActivitysBean item) {
        GlideUtil.loadRoundmage(helper.getView(R.id.iv_image), StringUtils.getFullUrl(item.getPosters(), 0));
        helper.setText(R.id.tv_buy, "已购票");
        if(item.getActivityStatus()==ACTIVITY_STATUS_WEIKAISHI){
            helper.setText(R.id.tv_state, "未开始");
            helper.setBackgroundRes(R.id.tv_state, R.drawable.shape_buy_gray);
        } if(item.getActivityStatus()==ACTIVITY_STATUS_JINXINZHONG){
            helper.setText(R.id.tv_state, "活动中");
            helper.setBackgroundRes(R.id.tv_state, R.drawable.shape_buy);
        } if(item.getActivityStatus()==ACTIVITY_STATUS_YIJIESHU){
            helper.setText(R.id.tv_state, "已结束");
            helper.setBackgroundRes(R.id.tv_state, R.drawable.shape_buy_gray);
        }
        helper.setText(R.id.tv_title,item.title);
        helper.setBackgroundRes(R.id.tv_buy, R.drawable.shape_buy_gray);
    }

    @Override
    protected void getData() {
            BaseSubscriber2<List<ActivitysBean>> baseSubscriber = HttpMethods.getInstance().getHttpService().getTicketRecord(UserInfoBean.getInstance().getToken(), page, getPageSize()).compose(RxHelper.getData()).subscribeWith(new BaseSubscriber2<List<ActivitysBean>>(this) {
                @Override
                public void onNext(List<ActivitysBean> o) {
                    doData(o);
                }
            });
            addDispose(baseSubscriber);
    }


    @Override
    public void initListener() {
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                ActivityUtil.startActivity(mContext,OrderDetailActivity.class,datas.get(position).orderId);
            }
        });
    }
}
